#include "networkmessage.h"

NetworkMessage::NetworkMessage() : type("") {
}

NetworkMessage::NetworkMessage(QString type) {
    setType(type);
}

void NetworkMessage::setData(QString key, QString value) {
    dataStorage.insert(key, value);
}

QString NetworkMessage::getData(QString key) {
    return dataStorage.value(key);
}

void NetworkMessage::setType(QString type) {
    this->type = type;
}

QString NetworkMessage::getType() {
    return type;
}

QString NetworkMessage::serialize() {
    QString message = "";

    message.append(QString("<%1>").arg(getType()));

    QMap<QString, QString>::iterator i;
     for (i = dataStorage.begin(); i != dataStorage.end(); ++i) {
         QString line = QString("<%1>%2</%3>").arg(i.key(), i.value(), i.key());
         message.append(line);
     }

     message.append(QString("</%1>").arg(getType()));

    //qDebug() << "[NetworkManager] Message serialized to '" << message << "'";

    return message;
}
